/*
 * This file is part of Plop Messenger.
 *
 * Plop Messenger is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 *  Plop Messenger is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Plop Messenger.  If not, see <http://www.gnu.org/licenses/>.
 */
package pm.util;

import java.util.Collection;
import java.util.Iterator;

public class ModifiableIterator<E> implements Iterable<E>, Iterator<E> {

	private Collection<? extends E> collection;
	private int i = 0;
	private E[] items;

	@SuppressWarnings("unchecked")
	public ModifiableIterator(Collection<? extends E> collection) {
		super();
		this.collection = collection;
		this.items = (E[]) collection.toArray();
	}

	@Override
	public boolean hasNext() {
		while (i < items.length) {
			if (collection.contains(items[i]))
				return true;
			else
				i++;
		}
		return false;
	}

	@Override
	public Iterator<E> iterator() {
		return this;
	}

	@Override
	public E next() {
		E item = items[i];
		i++;
		return item;
	}

	@Override
	public void remove() {
		// TODO Auto-generated method stub

	}

}
